const { needParam } = require("../../utils");
const { getWhereStr } = require("./_utils");
const { getSomeFieldNames, getStandFieldNames } = require("../../compile/mysql/_utils");

/**
 * 获取表格的信息
 * @param {count|''} type 获取表格的类型
 */
exports.getTable = function (name = needParam(), type = "count", { where, order, limits, group, having }) {
  if (type === "count") {
    let sql = `SELECT COUNT(*) AS count FROM ${name}`;
    const whereStr = getWhereStr(where, getStandFieldNames(["*"], name));
    if (whereStr) sql += ` WHERE ${whereStr}`;
    return `${sql};`;
  } else {
    throw new Error(`暂未处理类型：${type}`);
  }
};
